import 'package:dio/dio.dart';
import 'package:f_demo_one/components/16_shopList.dart';
import 'package:f_demo_one/components/22_order_detail.dart';
import 'package:flutter/material.dart';

class MyApp21 extends StatefulWidget {
  const MyApp21({super.key});

  @override
  State<MyApp21> createState() => _MyApp21State();
}

class _MyApp21State extends State<MyApp21> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    getData();
  }

  void getData() async {
    // 1. 准备请求地址
    String path = 'https://api-harmony-teach.itheima.net/hm/question/type';

    // 2. 创建http client
    Dio dio = Dio();

    // 3. 发送网络请求，得到响应
    Response response = await dio.get(path);
    // 4. 提取订单列表数据
    print(response.data);
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        //跳转方式1
        //   Navigator.push(
        //     context,
        //     MaterialPageRoute(
        //       builder: (context) => const OrderDetail(goodsId: 'sk001'),
        //     ),
        //   );
        //跳转方式2
        Navigator.pushNamed(
          context,
          '/detail',
          arguments: {'goodsId': 'sk999', 'name': '小明'},
        );
      },
      child: Scaffold(
        //导航条
        appBar: AppBar(
          title: const Text(
            'ListViewBuilder',
            style: TextStyle(color: Colors.white, fontSize: 20),
          ),
          backgroundColor: Colors.pink,
          centerTitle: true,
        ),
        //主体区域
        body: ListView.separated(
          //列表的每一项
          itemBuilder: (BuildContext context, int index) {
            return ShopList();
          },
          separatorBuilder: (BuildContext context, int index) {
            return Container(
              //
              height: 1,
              color: Colors.red,
              margin: const EdgeInsets.only(left: 10, right: 10),
              // child: const Divider(height: 1),
            );
          },
          itemCount: 20,
        ),
      ),
    );
  }
}
